* May 23, 2025
* Duffy, Lebeau, Puzzello

* This file replicates the results found in Tables 8, 9 in the main text; Table D5 in the Online Appendix.
* It also includes Figure 12 in the main text and Figure E1 in the Online Appendix. 
* The "Variable creation" block must be run first (after setting the directory). Other blocks can then be run independently.

* Important: the "Data import and variable creation" block must be run first (after setting the directory). Other blocks can then be run independently. 
 
*****************************************
*** Data import and variable creation ***
*****************************************

* Set directory
* cd "c:\user|lenovo\desktop\replication_DLP\utility" \\ Example
cd "c:\...\replication_DLP\utility"

use all_bids.dta
* This .dta file contains all proposals made. Each row corresponds to a proposal. Note that an accepted proposal shows twice: first when it is offered, second when it is accepted.

gen uniqueid = session * 10 + participantid_in_session - 10

gen buyersurplus = 74.1752*(quantity^0.6) - payment
gen sellersurplus = payment - 8.23249*(quantity^1.51678)
gen totalsurplus = buyersurplus + sellersurplus
gen bratio = buyersurplus / totalsurplus

gen firsthalf=1 if round <=15
replace firsthalf=0 if missing(firsthalf)
gen secondhalf=abs(1-firsthalf)

gen prob=0.5 if treathalf==1
replace prob=0.25 if treatquarter==1
replace prob=1 if missing(prob)

sort session round group timestamp
by session round group (timestamp): gen group_bid_number = _n


*********************************
*** Table 7 (columns 1 and 2) ***
*********************************

xtreg bratio if etokens==315 & role==2 & prob==1 & count==1, i(uniqueid) re vce(cluster session)  
xtreg bratio if etokens==60 & role==2 & prob==1 & count==1, i(uniqueid) re vce(cluster session)  
xtreg bratio if etokens==30 & role==2 & prob==1 & count==1, i(uniqueid) re vce(cluster session)  
xtreg bratio if etokens==315 & role==2 & treathalf==1 & count==1, i(uniqueid) re vce(cluster session)  
xtreg bratio if etokens==315 & role==2 & treatquarter==1 & count==1, i(uniqueid) re vce(cluster session)


*****************
*** Table 9 *****
*****************

preserve
sort session round group
egen numberoffers = count(participantid_in_session), by (session round group) 
replace numberoffers=numberoffers-1 if agreement==1 
collapse (first) numberoffers etokens agreement secondhalf, by(session round group)
tab agreement secondhalf, sum(numberoffers)
tab agreement secondhalf if etokens == 30, sum(numberoffers)
tab agreement secondhalf if etokens == 60, sum(numberoffers)
tab agreement secondhalf if etokens == 315, sum(numberoffers)
restore

************************
*** Figures 10 and E1 ***
************************

preserve
drop if agreement == 0
drop if session >= 7
sort session round group role timestamp
gen buyerlastoffer=1 if (round[_n+1]!=round[_n] | group[_n+1]!=group[_n] | role[_n+1]!=role[_n]) & role==2
gen buyersectolastoffer=1 if buyerlastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==2
gen buyerthirdtolastoffer=1 if buyersectolastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==2
gen buyerfourthtolastoffer=1 if buyerthirdtolastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==2
gen sellerlastoffer=1 if (round[_n+1]!=round[_n] | group[_n+1]!=group[_n] | role[_n+1]!=role[_n]) & role==1
gen sellersectolastoffer=1 if sellerlastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==1
gen sellerthirdtolastoffer=1 if sellersectolastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==1
gen sellerfourthtolastoffer=1 if sellerthirdtolastoffer[_n+1]==1 & group[_n+1]==group[_n] & round[_n+1]==round[_n] & role==1

sort role etokens sellerlastoffer sellersectolastoffer sellerthirdtolastoffer sellerfourthtolastoffer buyerlastoffer buyersectolastoffer buyerthirdtolastoffer buyerfourthtolastoffer
keep role buyersurplus sellersurplus sellerlastoffer sellersectolastoffer sellerthirdtolastoffer sellerfourthtolastoffer buyerlastoffer buyersectolastoffer buyerthirdtolastoffer buyerfourthtolastoffer etokens
gen buyershare=buyersurplus/(buyersurplus+sellersurplus)
gen sellershare=1-buyershare

* Data was compiled into excel (convergence.xlsx), then imported into MATLAB to create the graphs (main_figures.m)

restore

***********************
*** Tables 8 and D5 ***
***********************

** Important: The "Data important and variable creation" block
** needs to be run again after producing Tables 8 and D5 so as to
** produce other tables and figures in this file

preserve
drop if group_bid_number!=1
rename role firstofferrole
rename buyersurplus firstofferbuyersurplus
rename sellersurplus firstoffersellersurplus
rename totalsurplus firstoffertotalsurplus
save "first_offers.dta"
restore

* Table 8
clear all
use final_bids.dta
preserve
keep if session <= 6
drop if role==1 
merge 1:1 session round group using first_offers
drop if agreement==0
keep if session <= 6
gen buyersurplus = 74.1752*(quantity^0.6) - payment
gen sellersurplus = payment - 8.23249*(quantity^1.51678)
gen totalsurplus = buyersurplus + sellersurplus
gen buyershare = buyersurplus / totalsurplus
gen sellershare=1-buyershare
keep session round group buyersurplus sellersurplus buyershare firstofferrole firstofferbuyersurplus firstoffersellersurplus uniqueid
gen firstofferbuyershare=firstofferbuyersurplus/(firstofferbuyersurplus+firstoffersellersurplus)
gen diffbuyershare=buyershare-firstofferbuyershare
gen buyer=1 if firstofferrole==2
replace buyer=0 if missing(buyer)
xtreg diffbuyershare buyer, i(uniqueid) re vce(cluster session) 
restore 

* Table D5
preserve
keep if session <= 6
drop if role==2
merge 1:1 session round group using first_offers
drop if agreement==0
keep if session <= 6
gen buyersurplus = 74.1752*(quantity^0.6) - payment
gen sellersurplus = payment - 8.23249*(quantity^1.51678)
gen totalsurplus = buyersurplus + sellersurplus
gen buyershare = buyersurplus / totalsurplus
gen sellershare=1-buyershare
keep session round group buyersurplus sellersurplus sellershare firstofferrole firstofferbuyersurplus firstoffersellersurplus uniqueid
gen firstoffersellershare=firstoffersellersurplus/(firstofferbuyersurplus+firstoffersellersurplus)
gen diffsellershare=sellershare-firstoffersellershare
gen seller=1 if firstofferrole==1
replace seller=0 if missing(seller)
xtreg diffsellershare seller, i(uniqueid) re vce(cluster session) 
restore
erase first_offers




